package com.bbc.wigeth;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import com.bbc.R;

/**
 * Created by Administrator on 2017/9/27.
 */

public class MyFreeAttrs extends View {

    private Paint mPaint;
    private String text = "你好了llllll";

    public MyFreeAttrs(Context context) {
        super(context, null);
    }

    public MyFreeAttrs(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyFreeAttrs);
        int color = typedArray.getColor(R.styleable.MyFreeAttrs_mycolor, 0XFFFFFFFF);
        float dimension = typedArray.getDimension(R.styleable.MyFreeAttrs_mysize, 30);
        String string = typedArray.getString(R.styleable.MyFreeAttrs_myfr);
        mPaint.setTextSize(dimension);
        mPaint.setColor(color);
        typedArray.recycle();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPaint.setColor(Color.RED);
        mPaint.setStrokeWidth(10);
        mPaint.setStyle(Paint.Style.FILL);
        canvas.drawRect(new Rect(30, 50, 200, 200), mPaint);
        mPaint.setColor(Color.BLUE);
        canvas.drawText(text, 50, 300, mPaint);
    }
}
